import {WidgetClass} from "./widget";

export class WidgetLevel extends WidgetClass {
  constructor(options = {}) {
    super(options);
    const {ports, UI} = options;
    if (UI) {
      this.UI.data = UI.data;
    } else {
      this.UI.data = {
        layout: "vertical",
        valueColor: "success-color",
        trackColor: "component-stroke",
        minLimit: 0,
        maxLimit: 100,
      };
    }

    if (ports) {
      this.ports = ports;
    } else {
      this.ports = this.assembleDefaultPorts();
    }
  }

  assembleDefaultState(options = {}) {
    const superState = super.assembleDefaultState(options);
    return {
      ...superState,
      values: {
        value: 0,
      },
    };
  }

  assembleDefaultPorts() {
    const superState = super.assembleDefaultPorts();
    return {
      ...superState,
      values: [
       ...superState.values,
        {
          name: "进度",
          key: "value",
          type: "double",
          value: 0.0,
        },
      ],
      events: [
        ...superState.events
      ],
    };
  }
}
